package org.aceor.mddal.unit.gateway.sqlparser;

import com.google.common.base.Preconditions;
import org.aceor.mddal.common.sqlparser.result.SQLParsedResult;
import org.aceor.mddal.config.sharding.LogicTable;
import org.aceor.mddal.gateway.router.Router;
import org.aceor.mddal.gateway.sqlparser.SQLParserFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by lxue on 16/4/15.
 */
public class Main {
    Class<?> clazz = Main.class;

    ApplicationContext applicationContext;
    Router router;

    @Before
    public void init() {
        applicationContext = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
        Preconditions.checkNotNull(applicationContext);
        router = Router.getInstance(applicationContext.getBean(LogicTable.class));
        Preconditions.checkNotNull(router);
    }

    @Test
    public void test_groupby_orderby_limit_parse(){
        String sql = "select * from t_simple_stu where id > 12 group by age order by age limit 2,3";
        SQLParsedResult result = SQLParserFactory
                .createSQLParserEngine(sql,null, router.getAllTableShardingColumnsMapping())
                .parse();
    }
}
